package com.longblog.web.controller.login;

import com.longblog.web.service.login.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping
public class LoginController {

    @Autowired
    private LoginService loginService;

    @RequestMapping("/ck")
    public String ckeditor(){
        return "blog/edit";
    }
    @RequestMapping("/test")
    public String test(){
        return "blog/view";
    }
    /**
     * 跳转登录页面
     * @author  lilonglong
     * @date 2019/10/8 18:27
     */
    @RequestMapping("/login")
    public String loginPage(){
        return "login/login";
    }


    /**
     * 登录
     * @author  lilonglong
     * @date 2019/10/8 18:28
     */
    @PostMapping("/dologin")
    public String doLogin(String username, String password, ModelMap model){
        String result = loginService.login(username, password);
        if("success".equals(result)){
            return "index";
        }
        model.put("errorMsg",result);
        return "login/login2";
    }
}
